package com.interview.core.criteriaconditionquery;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;

import static org.springframework.data.jpa.domain.Specifications.where;
import static org.springframework.data.jpa.domain.Specifications.not;

import com.interview.core.modelutils.ModelUtils;



public abstract class CriteriaConditionQuery<T extends Object> {
	
	protected String id;
	protected Class<T> entityClass;
	protected Pageable pageable;
	protected Integer pageIndex = 0;
	protected Integer pageSize = 10;
	protected Integer totalPage ;
	
	public void setTotalPage(Integer totalPage){
		this.totalPage=totalPage;
	}
	
	public Integer getTotalPage(){
		return totalPage;
	}
	
	public Integer getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public CriteriaConditionQuery() {
		entityClass = ModelUtils.getUniquenessGenericClass(getClass());
	}
    
	public Pageable getPageable() {
		if(pageable == null){
			pageable = new PageRequest(pageIndex, pageSize , getSort());
		}
		return pageable;
	}

	public void setPageable(Pageable pageable) {
		this.pageable = pageable;
	}
	
	public Sort getSort(){
		return new Sort("id");
	}

	public abstract Specification<T> buildSpecification();
}


